package com.hongkl.demo5;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Optional;

public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("main.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 420, 640);
        stage.setTitle("Hello!");
        stage.setScene(scene);
        stage.show();

//        Platform.setImplicitExit(false);
//        stage.setOnCloseRequest(event->{
//            event.consume();
//            Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
//            alert.setTitle("退出程序");
//            alert.setHeaderText(null);
//            alert.setContentText("确认是否要退出程序？");
//            Optional<ButtonType> result = alert.showAndWait();
//            if (result.get() == ButtonType.OK){
//                stage.close();
//            }
//        });
//
//        stage.setTitle("设置关闭窗口的监听事件");
//        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}